<?php if($version == 'shop') { ?>

<div style="width: 750px; margin: 0 auto; font-family:calibri;">
    <table style="border-collapse: collapse;">
        <tr colspan="5">
            <td style="font-size: 30px;"><strong>Shoplist</strong></td>
        </tr>
        <tr height="20px"></tr>
    </table>
    <table style="border-collapse: collapse; font-size: 12px;">
        <tr style="border-top: 1px solid black; border-bottom: 1px solid black; font-weight: bold; font-size: 15px;">
            <td width="90px">Material No.</td>
            <td width="180px">Name</td>
            <td width="180px">Type</td>
            <td width="140px">Supplier</td>
            <td width="60px">Quantity</td>
            <td width="60px" style="text-align: right;">Unit</td>
        </tr>
        
        <?php if(isset($_SESSION['shoppinglist'])){
            foreach($_SESSION['shoppinglist'] as $session) {
                echo '<tr>';
                echo '<td>'.$session['number'].'</td>';
                echo '<td>'.$session['name'].'</td>';
                echo '<td>'.$session['type'].'</td>';
                
                //check what company name belongs to the supplier
                $supplierid = $session['supplier'];
                if($supplierid != null){
                    $supplier = ContactTable::getInstance()->findOneBy('id', $supplierid);
                    echo '<td>'.$supplier->getName().'</td>';
                } else { echo '<td>'.null.'</td>'; }
                
                echo '<td>'.$session['amount'].'</td>';
                echo '<td style="text-align: right;">'.$session['unit'].'</td>';
                echo '</tr>';
            }
        }
        ?>
    </table>
</div>

<?php } if($version == 'clear') { ?>

<div style="width: 750px; margin: 0 auto; font-family:calibri;">
    <table style="border-collapse: collapse;">
        <tr colspan="5">
            <td style="font-size: 30px;"><strong>Received purchases</strong></td>
        </tr>
        <tr height="20px"></tr>
    </table>
    <table style="border-collapse: collapse;">
        <tr style="border-top: 1px solid black; border-bottom: 1px solid black; font-weight: bold; font-size: 15px;">
            <td width="90px">Material No.</td>
            <td width="180px">Name</td>
            <td width="180px">Type</td>
            <td width="140px">Supplier</td>
            <td width="60px">Quantity</td>
            <td width="60px">Unit</td>
            <td width="100px" style="text-align: right;">Price</td>
        </tr>
        <?php if(isset($_SESSION['clearinglist'])){
            foreach($_SESSION['clearinglist'] as $session) {
                echo '<tr>';
                echo '<td>'.$session['number'].'</td>';
                echo '<td>'.$session['name'].'</td>';
                echo '<td>'.$session['type'].'</td>';
                echo '<td>'.$session['supplier'].'</td>';               
                echo '<td>'.$session['amount'].'</td>';
                echo '<td>'.$session['unit'].'</td>';
                echo '<td style="text-align: right;">'.$session['price'].'</td>';
                echo '</tr>';
            }
        }

        ?>
    </table>
</div>

<?php } if($version == 'received') { ?>

<div style="width: 750px; margin: 0 auto; font-family:calibri;">
    <table style="border-collapse: collapse;">
        <tr colspan="5">
            <td style="font-size: 30px;"><strong>Received Purchases</strong></td>
        </tr>
        <tr height="20px"></tr>
    </table>
    <table style="border-collapse: collapse;">
        <tr style="border-top: 1px solid black; border-bottom: 1px solid black; font-weight: bold; font-size: 15px;">
            <td width="90px">Material No.</td>
            <td width="180px">Name</td>
            <td width="180px">Type</td>
            <td width="140px">Supplier</td>
            <td width="60px">Quantity</td>
            <td width="60px">Unit</td>
            <td width="100px" style="text-align: right;">Price</td>
        </tr>
        <?php if(isset($_SESSION['purchaselist'])){
            foreach($_SESSION['purchaselist'] as $session) {
                if($session['status'] == 'received'){
                    echo '<tr>';
                    echo '<td>'.$session['number'].'</td>';
                    echo '<td>'.$session['name'].'</td>';
                    echo '<td>'.$session['type'].'</td>';
                    
                 //check what company name belongs to the supplier
                $supplierid = $session['supplier'];
                if($supplierid != null){
                    $supplier = ContactTable::getInstance()->findOneBy('id', $supplierid);
                    echo '<td>'.$supplier->getName().'</td>';
                } else { echo '<td>'.null.'</td>'; }
                    
                    echo '<td style="text-align: right;">'.$session['amount'].'</td>';
                    echo '<td style="text-align: right;">'.$session['unit'].'</td>';
                    echo '<td style="text-align: right;">'.$session['price'].'</td>';
                    echo '</tr>';
                }
            }
        }

        ?>
    </table>
</div>
<?php } ?>
<?php if($version == 'minimum') { ?>

<div style="width: 750px; margin: 0 auto; font-family:calibri;">
    <table style="border-collapse: collapse;">
        <tr colspan="5">
            <td style="font-size: 30px;"><strong>Materials under minimum</strong></td>
        </tr>
        <tr height="20px"></tr>
    </table>
    <table style="border-collapse: collapse;">
        <tr style="border-top: 1px solid black; border-bottom: 1px solid black; font-weight: bold; font-size: 15px;">
            <td width="90px">Material No.</td>
            <td width="180px">Name</td>
            <td width="180px">Type</td>
            <td width="140px">Minimum</td>
            <td width="60px">Stock</td>
            <td width="60px">Unit</td>
        </tr>
        <?php 
            foreach($materials as $material){ ?>
        <tr>
            <td><?php echo $material->getPartNumber() ?></td>
            <td><?php echo $material->getName() ?></td>
            <td><?php echo $material->getType() ?></td>
            <td><?php echo $material->getMinStock() ?></td>
            <td><?php echo $material->getStock() ?></td>
            <td><?php echo $material->getUnit() ?></td>
        </tr>
         <?php }
        ?>
    </table>
</div>
<?php } ?>